package com.atguigu;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Random;

/**
 * 秒杀案例
 */
public class SecKillServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //每个用户只能秒杀一次（实际中应该从session中获取userId）
		String userid = new Random().nextInt(50000) +"" ;
		//获取要秒杀的商品的Id
		String prodid =request.getParameter("prodid");

		//1 存在超卖问题
		String result=SecKill1.doSecKill(userid,prodid);
		//2 解决超卖问题
		//String result=SecKill2.doSecKill(userid,prodid);
        //3 解决库存遗留问题
		//boolean isSuccess= SecKill3.doSecKill(userid,prodid);
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(result);
		//System.out.println(isSuccess);
	}
}
